define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
	const controller = {
		index() {
			Table.api.init({
				extend: {
					index_url: 'product/product/index',
					add_url: 'product/product/add',
					edit_url: 'product/product/edit',
					del_url: 'product/product/del',
					multi_url: 'product/product/multi',
					table: 'product',
				},
			});

			const table = $('#table');

			table.bootstrapTable({
				// 请求地址
				url: $.fn.bootstrapTable.defaults.extend.index_url,
				// 设置工具栏元素
				toolbar: '.toolbar',
				// 设置主键
				pk: 'id',
				// 排序字段
				sortName: 'createtime',
				// 默认排序方式
				sortOrder: 'desc',
        showExport: false,
        fixedColumns: true,
        fixedRightNumber: 1,
				// 渲染表格数据
				columns: [
					{ checkbox: true },
					{ field: 'id', title: __('Id'), sortable: true },
					{ field: 'name', title: __('Name'), operate: 'LIKE' },
					{
						field: 'status',
						title: __('Status'),
						searchList: { 0: __('下架'), 1: __('上架') },
						formatter: Table.api.formatter.flag,
					},
					{
						field: 'flag',
						title: __('Flag'),
						searchList: { 1: __('新品'), 2: __('热销'), 3: __('推荐') },
						formatter: Table.api.formatter.flag,
					},
					{ field: 'stock', title: __('Stock') },
					{ field: 'price', title: __('Price') },
					{ field: 'type.name', title: __('Typeid') },
					{ field: 'unit.name', title: __('Unitid') },
					{
						field: 'createtime',
						title: __('Createtime'),
						operate: 'RANGE',
						addclass: 'datetimerange',
						autocomplete: false,
						formatter: Table.api.formatter.datetime,
					},
					{
						field: 'operate',
						title: __('Operate'),
						table: table,
						events: Table.api.events.operate,
						formatter: Table.api.formatter.operate,
					}
				],
			});

			Table.api.bindevent(table);
		},
		add() {
			controller.api.bindevent();
		},
		edit() {
			controller.api.bindevent();
		},
		del() {
			controller.api.bindevent();
		},
		api: {
			// JS模块化的全局方法
			bindevent: function () {
				Form.api.bindevent($('form[role=form]'));
			},
		},
	};

	return controller;
});
